package com.zdkj.subway.support.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdkj.common.core.util.R;
import com.zdkj.common.data.mybatis.wrapper.CustomQueryWrapper;
import com.zdkj.common.log.annotation.SysLog;
import com.zdkj.common.security.util.ObjectUtils;
import com.zdkj.subway.support.dto.in.SwParamStTicketTypeDTO;
import com.zdkj.subway.support.entity.SwParamStTicketType;
import com.zdkj.subway.support.service.SwParamStTicketTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * 票库车票类型表
 *
 * @author cui_com
 * @date 2020-01-08 17:13:41
 */
@RestController
@AllArgsConstructor
@RequestMapping("/swparamsttickettype")
@Api(value = "swparamsttickettype", tags = "票库车票类型表管理")
public class SwParamStTicketTypeController {

    private final SwParamStTicketTypeService swParamStTicketTypeService;

    /**
     * 分页查询详细信息
     *
     * @param page                分页对象
     * @param swParamStTicketTypeDTO 票库车票类型表
     * @return
     */
    @ApiOperation(value = "分页查询详细信息", notes = "分页查询详细信息")
    @GetMapping("/detail/page")
    public R getSwParamStTicketTypeDetailPage(Page page, SwParamStTicketTypeDTO swParamStTicketTypeDTO) {
        return R.ok(swParamStTicketTypeService.queryDetailByPage(
                page, new CustomQueryWrapper(SwParamStTicketType.class)
                        .addDTO(swParamStTicketTypeDTO)
                        .init()));
    }

    /**
     * 分页查询
     *
     * @param page                分页对象
     * @param swParamStTicketType 票库车票类型表
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    public R getSwParamStTicketTypePage(Page page, SwParamStTicketType swParamStTicketType) {
        return R.ok(swParamStTicketTypeService.page(page, Wrappers.query(swParamStTicketType)));
    }


    /**
     * 通过id查询票库车票类型表
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}")
    public R getById(@PathVariable("id") Integer id) {
        return R.ok(swParamStTicketTypeService.getById(id));
    }

    /**
     * 新增票库车票类型表
     *
     * @param swParamStTicketType 票库车票类型表
     * @return R
     */
    @ApiOperation(value = "新增票库车票类型表", notes = "新增票库车票类型表")
    @SysLog("新增票库车票类型表")
    @PostMapping
    @PreAuthorize("@pms.hasPermission('support_sw_param_st_ticket_type_add')")
    public R save(@RequestBody SwParamStTicketTypeDTO swParamStTicketType) {
        SwParamStTicketType defaultObj = ObjectUtils.getDefaultObj(SwParamStTicketType.class);
        BeanUtils.copyProperties(swParamStTicketType, defaultObj);
        return R.ok(swParamStTicketTypeService.save(defaultObj));
    }

    /**
     * 修改票库车票类型表
     *
     * @param swParamStTicketType 票库车票类型表
     * @return R
     */
    @ApiOperation(value = "修改票库车票类型表", notes = "修改票库车票类型表")
    @SysLog("修改票库车票类型表")
    @PutMapping
    @PreAuthorize("@pms.hasPermission('support_sw_param_st_ticket_type_edit')")
    public R updateById(@RequestBody SwParamStTicketTypeDTO swParamStTicketType) {
        SwParamStTicketType obj = new SwParamStTicketType();
        BeanUtils.copyProperties(swParamStTicketType, obj);
        return R.ok(swParamStTicketTypeService.updateById(obj));
    }

    /**
     * 通过id删除票库车票类型表
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除票库车票类型表", notes = "通过id删除票库车票类型表")
    @SysLog("通过id删除票库车票类型表")
    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('support_sw_param_st_ticket_type_del')")
    public R removeById(@PathVariable Integer id) {
        return R.ok(swParamStTicketTypeService.removeById(id));
    }

}
